package com.zxy.springboot_goods.controller;


import com.zxy.springboot_goods.config.AjaxResult;
import com.zxy.springboot_goods.entity.City;
import com.zxy.springboot_goods.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lenovo
 * @since 2021-11-04
 */
@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private ICityService cityService;
    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("getCity")
    public List<City> getCity(){
        String key = "city";
        List<City> list = null;
        Boolean hasKey = redisTemplate.hasKey(key);
        if(hasKey){
            list = redisTemplate.opsForList().range(key,0,-1);
        }else{
            list = cityService.getCity(1);
            redisTemplate.opsForList().leftPushAll(key,list);
        }
        return list;
    }

}
